package cc.yaomm.service.basic.controller.business.user.biz;

import cc.yaomm.common.basic.enums.StatusEnum;
import cc.yaomm.common.basic.util.BeanUtils;
import cc.yaomm.common.biz.enums.OwnerTypeEnum;
import cc.yaomm.service.basic.controller.business.BaseAdminBiz;
import cc.yaomm.service.basic.controller.business.user.vo.RoleParamVO;
import cc.yaomm.service.basic.controller.business.user.vo.RoleResultVO;
import cc.yaomm.service.basic.service.user.RoleService;
import cc.yaomm.service.basic.service.user.bo.RoleParamBO;
import cc.yaomm.service.basic.service.user.bo.RoleResultBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleBiz extends BaseAdminBiz {

    @Autowired
    private RoleService roleService;

    /**
     * 分页
     *
     * @param paramVO
     * @return
     */
    public List<RoleResultVO> findPage(RoleParamVO paramVO) {
        RoleParamBO paramBO = paramVO.convert(RoleParamBO.class);
        List<RoleResultBO> resultBOList = roleService.findPage(paramBO);
        return BeanUtils.mapList(resultBOList, RoleResultVO.class);
    }

    /**
     * 统计
     *
     * @param paramVO
     * @return
     */
    public Integer countPage(RoleParamVO paramVO) {
        RoleParamBO paramBO = paramVO.convert(RoleParamBO.class);
        return roleService.countPage(paramBO);
    }

    /**
     * create/edit role
     *
     * @param paramVO
     */
    public void save(RoleParamVO paramVO) {
        RoleParamBO paramBO = paramVO.convert(RoleParamBO.class);
        paramBO.setOwnerType(OwnerTypeEnum.BIZ);
        paramBO.setUpdateBy(super.getUserName());
        roleService.save(paramBO);
    }

    /**
     * 锁定/解锁角色
     *
     * @param paramVO
     */
    public void lock(RoleParamVO paramVO) {
        roleService.lock(paramVO.getId(), paramVO.getStatus());
    }

    /**
     * 角色设置权限
     */
    public void setPermission(RoleParamVO paramVO) {
        roleService.setPermission(paramVO.getId(), paramVO.getPermissionIds());
    }

}
